package com.hzqx.syndata.result;


import com.hzqx.syndata.result1.Result;
import com.hzqx.syndata.result1.ResultBuilder;
import com.hzqx.syndata.result1.ResultEnum;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

@ControllerAdvice
public class GlobalExceptionHandler {

    /**
     * 处理自定义异常
     *
     */
    @ExceptionHandler(value = DefinitionException.class)
    @ResponseBody
    public ResultJson bizExceptionHandler(DefinitionException e) {

        return ResultJson.defineError(e);
    }

    /**
     * 处理其他异常
     * @return
     */
    @ExceptionHandler(value = RuntimeException.class)
    @ResponseBody
    public Result exceptionHandler(Exception e) {
        //return ResultJson.otherError(ErrorEnum.INTERNAL_SERVER_ERROR);
        return ResultBuilder.error(ResultEnum.SYSTEM_ERROR,e.getMessage());
    }
}
